#pragma once

#include <iostream>
#include <string>
#include <ctemplate/template.h>

//#include "oj_model.hpp"
#include "oj_model2.hpp"

namespace ns_view
{
    using namespace ns_model;

    const std::string template_path = "./template_html/";

    class View
    {
    public:
        View(){}
        ~View(){}
    public:
       //构建所有题目的网页信息
        void AllExpandHtml(const vector<struct Question>&questions,string * html )
        {
            //1.获取要被渲染的 html 文件路径
            const string src_html=template_path+"all_questions.html";
            //2.形成数据字典ssss
            ctemplate::TemplateDictionary root("all_questions");
            for(const auto& q:questions)
            {
                //形成数据字典的子字典
                ctemplate::TemplateDictionary* sub=root.AddSectionDictionary("questions_list");
                sub->SetValue("number",q.number);
                sub->SetValue("title",q.title);
                sub->SetValue("star",q.star);
            }
            //3.获取要被渲染的html
            ctemplate::Template* tp=ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);
            //4.开始完成渲染
            tp->Expand(html,&root);
        }
       //构建单个题目的网页信息
        void OneExpandHtml(const struct Question& question,string* html)
        {
            //1.获取要被渲染的 html 文件路径
            const string src_html=template_path+"one_question.html";
            //2.形成数据字典
            ctemplate::TemplateDictionary root("one_quest");
            root.SetValue("number",question.number);
            root.SetValue("title",question.title);
            root.SetValue("star",question.star);
            root.SetValue("desc",question.desc);
            root.SetValue("pre_code",question.header);
            //3.获取要被渲染的html
            ctemplate::Template* tp=ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);
            //4.开始完成渲染
            tp->Expand(html,&root);

        }
    };
}
